#include <iostream>
#include <fstream>
#include "contact.pb.h"
#include <string>
void PrintContacts(contacts2::Contacts &contacts)
{
    for (int i = 0; i < contacts.contacts_size(); i++)
    {
        std::cout << "*********输入联系人*********" << std::endl;
        const contacts2::PeopleInfo &people = contacts.contacts(i);
        std::cout << "联系人姓名：" << people.name() << std::endl;
        std::cout << "联系人年龄：" << people.age() << std::endl;

        switch (people.other_contact_case())
        {
        case PeopleInfo::OtherContactCase::kQq:
            cout << "qq号: " << people.qq() << endl;
            break;
        case PeopleInfo::OtherContactCase::kWeixin:
            cout << "微信号: " << people.weixin() << endl;
            break;
        case PeopleInfo::OtherContactCase::OTHER_CONTACT_NOT_SET:
            break;
        }
        const Reflection *reflection = PeopleInfo::GetReflection();
        const UnknownFieldSet &unknowSet = reflection->GetUnknownFields(people);
        for (int j = 0; j < unknowSet.field_count(); j++)
        {
            const UnknownField &unknow_field = unknowSet.field(j);
            cout << "未知字段" << j + 1 << ":"
                 << " 字段编号: " << unknow_field.number()
                 << " 类型: " << unknow_field.type();
            switch (unknow_field.type())
            {
            case UnknownField::Type::TYPE_VARINT:
                cout << " 值: " << unknow_field.varint() << endl;
                break;
            case UnknownField::Type::TYPE_LENGTH_DELIMITED:
                cout << " 值: " << unknow_field.length_delimited() << endl;
                break;
            }
        }
    }
}
int main()
{
    contacts2::Contacts _con;
    // 读取
    std::fstream input("text.bin", std::ios::in | std::ios::binary);
    // if(!input) std::cout<<"file not exit"<<std::endl;
    if (!_con.ParseFromIstream(&input))
    {
        std::cerr << "parse error!" << std::endl;
        input.close();
        return -1;
    }
    // 打印通讯录列表
    PrintContacts(_con);

    return 0;
}